package com.atguigu.tingshu.album.rpc;

import com.atguigu.tingshu.album.service.AlbumInfoService;
import com.atguigu.tingshu.album.service.BaseCategoryService;
import com.atguigu.tingshu.album.service.TrackInfoService;
import com.atguigu.tingshu.common.result.Result;
import com.atguigu.tingshu.model.album.AlbumInfo;
import com.atguigu.tingshu.model.album.BaseCategory3;
import com.atguigu.tingshu.model.album.BaseCategoryView;
import com.atguigu.tingshu.model.album.TrackInfo;
import com.atguigu.tingshu.vo.album.AlbumStatVo;
import com.atguigu.tingshu.vo.album.TrackListVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("/rpc/inner/albumInfo")
public class AlbumInfoRpcController {

    @Autowired
    private AlbumInfoService albumInfoService;

    @Autowired
    private BaseCategoryService baseCategoryService;

    @Autowired
    private TrackInfoService trackInfoService;

    @GetMapping("/getAlbumInfoAndAttrValue/{albumId}")
    Result<AlbumInfo> getAlbumInfoAndAttrValue(@PathVariable(value = "albumId") Long albumId){
        AlbumInfo albumInfo = albumInfoService.getAlbumInfo(albumId);
        return Result.ok(albumInfo);
    }

    @GetMapping("/getAlbumCategory/{albumId}")
    Result<BaseCategoryView> getAlbumCategory(@PathVariable(value = "albumId") Long albumId){
        BaseCategoryView baseCategoryView = baseCategoryService.getAlbumCategory(albumId);
        return Result.ok(baseCategoryView);
    }

    @GetMapping("/getAlbumStat/{albumId}")
    Result<AlbumStatVo> getAlbumStat(@PathVariable(value = "albumId")Long albumId){
        AlbumStatVo albumStatVo =  albumInfoService.getAlbumStat(albumId);
        return Result.ok(albumStatVo);

    }


    @GetMapping("/getBaseCategory3ListByC1Id/{category1Id}")
    Result<List<BaseCategory3>> getBaseCategory3ListByC1Id(@PathVariable(value = "category1Id")Long category1Id){
        List<BaseCategory3> topBaseCategory3 = baseCategoryService.findTopBaseCategory3(category1Id);
        return Result.ok(topBaseCategory3);
    }

    @GetMapping("/getAllCategory1Id")
    Result<List<Long>> getAllCategory1Id(){
        List<Long> category1IdList = baseCategoryService.getAllCategory1Id();
        return Result.ok(category1IdList);
    }


    @PostMapping("/getTrackListByIds")
    Result<List<TrackListVo>> getTrackListByIds(@RequestBody List<Long> trackIdList){
        List<TrackListVo> trackListVoList  = trackInfoService.getTrackListByIds(trackIdList);
        return Result.ok(trackListVoList);
    }

    @GetMapping("/getAlbumInfoIdList")
    Result<List<Long>> getAlbumInfoIdList(){
        List<Long> albumIdList = albumInfoService.getAlbumInfoIdList();
        return Result.ok(albumIdList);
    }

    @GetMapping("/getTrackListByCurrentTrackId/{userId}/{trackId}/{trackCount}")
    Result<List<TrackInfo>> getTrackListByCurrentTrackId(@PathVariable(value = "userId") Long userId,
                                                         @PathVariable(value = "trackId")Long trackId,
                                                         @PathVariable(value = "trackCount")Integer trackCount){
        List<TrackInfo> trackInfoList = trackInfoService.getTrackListByCurrentTrackId(userId,trackId,trackCount);
        return Result.ok(trackInfoList);
    }

    @GetMapping("/getTrackInfoByTrackId/{trackId}")
    Result<TrackInfo> getTrackInfoByTrackId(@PathVariable(value = "trackId")  Long trackId){
        TrackInfo trackInfo = trackInfoService.getById(trackId);

        return Result.ok(trackInfo);
    }

    @GetMapping("/getAlbumInfoByTrackId/{trackId}")
    Result<AlbumInfo> getAlbumInfoByTrackId(@PathVariable(value = "trackId")Long trackId){
        AlbumInfo albumInfo = albumInfoService.getAlbumInfoByTrackId(trackId);
        return Result.ok(albumInfo);
    }




}
